package main;
import java.io.*;

public class objFileReader {
	// put objects form file to array of objects
	public static void file2obj(String filename, Object[] ob) {
		try {
			// create stream to write an object to file 
			FileInputStream fIn = new FileInputStream(new File(filename));
			ObjectInputStream ois = new ObjectInputStream(fIn);

			int countObj = 0; //
			cHocSinh temp;
			do {
				temp = (cHocSinh) ois.readObject();
				// break when no more object in file
				if (temp == null)
					break;
				// new cHocSinh object
				ob[countObj] = new cHocSinh();
				// 
				ob[countObj++] = temp;
			} while (true);

			ois.close();	//close stream
		} catch (ClassNotFoundException | IOException e) {
			System.out.println("Khong tim thay file");
			e.printStackTrace();
		}
		return;
	}
}
